@extends('layouts.home')
@extends('layouts.nav')
@extends('layouts.top')


@section('css')
    <link rel="stylesheet" type="text/css" href="{{ asset('files/js/jquery-multi-select/css/multi-select.css') }}"/>
@endsection

@section('heading')
    <h3>
        账号设置
    </h3>
    <ul class="breadcrumb">
        <li>
            <a href="#">用户管理</a>
        </li>
        <li class="active"> 角色新增</li>
    </ul>
@endsection


@section('wrapper')
    <section class="panel">
        <div class="panel-body">
            <div class="form">
                @if(isset($role))
                    <form method="POST" role="form" action="{{ route('role.update', $role->id) }}" class="cmxform form-horizontal adminex-form">
                        {{ method_field('PATCH') }}
                @else
                    <form method="POST" role="form" action="{{ route('role.store') }}" class="cmxform form-horizontal adminex-form">
                @endif
                        @csrf
                        <div class="form-group ">
                            <label for="cname" class="control-label col-lg-2">名称</label>
                            <div class="col-lg-5">
                                <input class=" form-control{{ $errors->has('name') ? ' error' : '' }}" id="cname"
                                       value="{{ $role->name or old('name') }}" name="name" minlength="2" type="text" required/>
                                @if ($errors->has('name'))
                                    <label class="error">{{ $errors->first('name') }}</label>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">权限选择</label>

                            <div class="col-md-9">
                                <select multiple="multiple" class="multi-select" id="my_multi_select1"
                                        name="permissions[]">
                                    @foreach($permissions as $permission)
                                        <option {{ isset($ids) && in_array($permission->id, $ids) ? 'selected' : '' }} value="{{ $permission->id }}">{{ $permission->name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-primary" type="submit">保存</button>
                            </div>
                        </div>
                    </form>
            </div>

        </div>
    </section>
@endsection

@section('js')
    <script type="text/javascript" src="{{ asset('files/js/jquery-multi-select/js/jquery.multi-select.js') }}"></script>
    <script type="text/javascript" src="{{ asset('files/js/jquery-multi-select/js/jquery.quicksearch.js') }}"></script>
    <script src="{{ asset('files/js/multi-select-init.js') }}"></script>
@endsection